<?php
/**
 * Created by PhpStorm.
 * User: gakuin
 * Date: 7/9/16
 * Time: 3:36 PM
 */
namespace app\models;

use app\common\CommonHelper;
use Yii;
use yii\db\ActiveRecord;
class Addressbook extends ActiveRecord
{

    public  function  getAddress(){

        $id = Yii::$app->user->id;
        $addresses = Addressbook::find()->where(['user_id' => $id,'del_flag'=>'1'])->orderBy('is_default DESC')->asArray()->all();
        return $addresses;

    }

    public  function  getDefaultAddress(){

        $id = Yii::$app->user->id;
        $address = Addressbook::find()->where([
                'user_id' => $id,
                'is_default'=>'1',
                'del_flag' => '1'
            ]
            )->asArray()->one();
        return $address;

    }

    public  function  getAddressById($addressId){

        $address = Addressbook::find()->where([
                'addressbook_id' => $addressId
            ]
        )->asArray()->one();
        return $address;

    }
}
